{% extends "base.html" %}

{% block js %}
<script src="/static/js/jquery.scrollUp.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){

$.scrollUp({
              scrollName: 'scrollUp', // Element ID
              topDistance: '300', // Distance from top before showing element (px)
              topSpeed: 300, // Speed back to top (ms)
              animation: 'fade', // Fade, slide, none
              animationInSpeed: 200, // Animation in speed (ms)
              animationOutSpeed: 200, // Animation out speed (ms)
              scrollText: '', // Text for element
              activeOverlay: false  // Set CSS color to display scrollUp active point, e.g '#00FFFF'
        });

$('.subscribeLink').click(function(){
        if ($(this).hasClass("restoreButton")) {return};

        $(this).html("订阅中");
        ajax_request(this, '订阅失败', true, function(t){
                $(t).removeClass("subscribeLink").addClass("restoreButton btn btn-default").html("已订阅");
                });

        return false;
        });
});

function ajax_request(t, m, d, callback)
{
        var href = $(t).attr('href');
        var url_parsed = /^\/subscribe\/([0-9]+)$/.exec(href);
        var id = url_parsed[1];
        if(!id) return false;
        if (href == '' || href =='#')
                return false
        $(t).attr('href', '###');
        //href = 'http://zhred.net'+href
        $.post(href, { 'ajax': 1 },
                        function(data){
                                if(data == 'ok') {
                                        if (callback)
                                                callback(t)
                                        else if (d != true)
                                                $('#tableViewCell' + id).hide();
                                        //$('.tableViewCell:last-child').addClass('tableViewCellLast');
				} else {
                                        alert(m);
                                }
                                return false;
                        }
              );
        return false;
}
</script>

<a id="scrollUp" href="#top" title="" style="position: fixed; z-index: 2147483647; display: none;"></a>
{% endblock %}



{% block content %}
<br/><p>
添加RSS，可以到<a href='http://www.douban.com/group/topic/49499883/' target='_blank'>豆瓣</a>留言。
</p>
<p><strong style="color:red;">最多可订阅10个。</strong></p>

{% if level == 3 %}
<div class="panel panel-primary">
            <div class="panel-heading">
              <h3 class="panel-title">自定义RSS</h3>
            </div>
            <div class="panel-body">
              <form action="" method="POST">
    <div class="book">
        <div class="titleRow">
            <input type="text" name="t" placeholder="标题" />
	    <label>是否全文:</label>
	    <input type="checkbox" name="full"/>
        </div>
        <div class="summaryRow">
            <input type="text" name="url" style="width:100%;"  placeholder="URL" />
	    <textarea name='descrip' rows="3" cols="70" placeholder="简介"></textarea>
	    
	    <p>
		<label>类型：</label>
		<select class="bool" name="category">
		{% for i in cate %}
			<option value="{{ i.c_id }}">{{ i.category_name }}</option>
		{% endfor %}
		</select>
	    </p>
	    <p>
	    	<label>更新周期：</label>
		<input type="text" name="up_t" placeholder="几小时" />
	    </p>
        </div>
	{% if tips %}<p style="color:red;font-size:0.7em;">{{tips}}</p>{% endif %}
    </div>
		<input type="submit" value="添加" class="btn btn-default" />
    </form>
            </div>
          </div>
{% endif %}



	{% set hasitem2 = [] %}
	{% for book in books %}
	{% if book.f_id not in ownfeeds %}
        <div class="panel panel-default">
	<div class="panel-heading">
          <h3 class="panel-title">{{book.title}}</h3>
	</div>
	<div class="panel-body">
          <p class="text-danger">{{book.descrip}}</p>

	  <div class="controls pull-right">
	{% if level == 3 %}
	  <a class="btn btn-primary" href="/delfeed/{{book.f_id}}" role="button">删除</a>
	{% endif %}
	  <a class="btn btn-primary subscribeLink" href="/subscribe/{{book.f_id}}" role="button">订阅</a>
	  </div>

        </div>
	</div>
	{% do hasitem2.append(1) %}
	{% endif %}
	{% endfor %}
	{% if not hasitem2 %}
	<p style="font-size:0.8em;color:grey;">暂时没有未订阅的书籍</p>
	{% endif %}

     
{% endblock %}
